package com.ldgame.entities;

import org.lwjgl.util.vector.Vector2f;

import com.ldgame.game.Victory;

public class Bullet extends Entity {
	public Bullet(Team team) {
		super(team);
		setRadius(4.0f);
		getSprite().setAnimFrames(1);
	}
	
	@Override
	public void handleCollisions(Entity entity) {
		if (enabled && entity.isEnabled() && Vector2f.sub(entity.getPosition(), getPosition(), null).length() < entity.getRadius() + getRadius()) {
			if (entity.getTeam() != team) {
				entity.setEnabled(false);
				if (entity.getTeam() == Team.TINY_HUMAN) {
					++Victory.humansKilled;
				} else {
					++Victory.aliensKilled;
				}
			}
			setEnabled(false);
		}
	}
	
	public void handlePlayerCollisions(Player player) {
		if (enabled && Vector2f.sub(player.getPosition(), getPosition(), null).length() < player.getRadius() + getRadius()) {
			if (player.getTeam() != team) {
				player.damage();
			}
			setEnabled(false);
		}
	}
	
	public void handleBuildingCollisions(Building building) {
		if (enabled && getPosition().x + getRadius() > building.getPosition().x - building.getRadius() &&
					   getPosition().x - getRadius() < building.getPosition().x + building.getRadius() &&
					   getPosition().y + getRadius() > building.getPosition().y - building.getRadius() &&
					   getPosition().y - getRadius() < building.getPosition().y + building.getRadius()) {
			setEnabled(false);
		}
	}
}